using System;
using FireStarter.Base;
using FireStarterModeller.BO;
using Habanero.Base.Exceptions;
using Habanero.BO.ClassDefinition;
using NUnit.Framework;

namespace FireStarterModeller.Test.BO
{
    /// <summary>
    /// Provides a place to write custom tests for UITab objects.
    /// This file is only written once and can be changed.  The Def file
    /// attached to this as a dependent is rewritten with each regeneration
    /// and contains the standard tests for UITab.
    /// Regenerate this test project whenever there have been changes to the
    /// business objects.
    /// If tests are failing due to a unique setup in your application,
    /// you can either override the Create methods in TestUtils, or you
    /// can add the test to the ignore list below and reimplement it here.
    /// </summary>
    public partial class TestUITab
    {
        [TestFixtureSetUp]
        public void SetupTestFixture()
        {
            //------------------------------------------------------------
            // Use this list to ignore generated tests that are failing
            // due to a unique condition in your application.
            // Remember to reimplement the test here.
            //------------------------------------------------------------
            //_ignoreList.Add("TestMethodName", "Reason for ignoring it");
            base.SetupFixture();
        }

        [Ignore("Need to implement ToString")] //TODO Brett 24 Feb 2009: Ignored Test - Need to implement ToString
        [Test]
        public void Test_ToString()
        {
            //---------------Set up test pack-------------------

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------

            //---------------Test Result -----------------------
            Assert.Fail("Implement ToString() for the Business object and implement this test");
        }

        [Test]
        public void Test_IUIFormTab_Name_Get()
        {
            //---------------Set up test pack-------------------
            UITab uITab = TestUtilsUITab.CreateUnsavedValidUITab();
            IUIFormTab formTab = uITab;

            //---------------Assert Precondition----------------
            Assert.Greater(uITab.Name.Length, 0);
            //---------------Execute Test ----------------------
            string name = formTab.Name;
            //---------------Test Result -----------------------
            Assert.AreEqual(uITab.Name, name);
        }

        [Test]
        public void Test_IUIFormTab_Name_Set()
        {
            //---------------Set up test pack-------------------
            UITab uITab = TestUtilsUITab.CreateUnsavedValidUITab();
            IUIFormTab formTab = uITab;
            string newName = TestUtilsShared.GetRandomString();

            //---------------Assert Precondition----------------
            Assert.AreNotEqual(newName, uITab.Name);
            //---------------Execute Test ----------------------
            formTab.Name = newName;
            //---------------Test Result -----------------------
            Assert.AreEqual(newName, uITab.Name);
        }

        [Test]
        public void Test_ICollection_Count()
        {
            //---------------Set up test pack-------------------
            UIColumnLayout columnLayout = TestUtilsShared.CreateUnsavedValidUIColumnLayoutInfo();
            UITab uiTab = columnLayout.UITab;
            IUIFormTab formTab = uiTab;
            //---------------Assert Precondition----------------
            Assert.IsNotNull(uiTab);
            Assert.AreEqual(1, uiTab.UIColumnLayouts.Count);
            //---------------Execute Test ----------------------
            int count = formTab.Count;

            //---------------Test Result -----------------------
            Assert.AreEqual(uiTab.UIColumnLayouts.Count, count);
        }

        [Test]
        public void Test_IUIFormTab_Contains_ReturnsTrue()
        {
            //---------------Set up test pack-------------------
            UIColumnLayout columnLayout = TestUtilsShared.CreateUnsavedValidUIColumnLayoutInfo();
            UITab uiTab = columnLayout.UITab;
            IUIFormTab formTab = uiTab;
            //---------------Assert Precondition----------------
            Assert.IsNotNull(uiTab);
            Assert.IsTrue(uiTab.UIColumnLayouts.Contains(columnLayout));
            //---------------Execute Test ----------------------
            bool contains = formTab.Contains(columnLayout);

            //---------------Test Result -----------------------
            Assert.IsTrue(contains); ;
        }


        [Test]
        public void Test_IUIFormTab_Contains_ReturnsFalse()
        {
            //---------------Set up test pack-------------------
            UITab uiTab = TestUtilsUITab.CreateUnsavedValidUITab();
            UIColumnLayout columnLayout = new UIColumnLayout();
            IUIFormTab formTab = uiTab;

            //---------------Assert Precondition----------------
            Assert.IsFalse(uiTab.UIColumnLayouts.Contains(columnLayout));
            //---------------Execute Test ----------------------
            bool contains = formTab.Contains(columnLayout);

            //---------------Test Result -----------------------
            Assert.IsFalse(contains);
        }

        [Test]
        public void Test_IUIFormTab_this()
        {
            //---------------Set up test pack-------------------
            UIColumnLayout columnLayout1 = TestUtilsShared.CreateUnsavedValidUIColumnLayoutInfo();
            UITab uiTab = columnLayout1.UITab;
            UIColumnLayout columnLayout2 = TestUtilsShared.CreateUnsavedValidUIColumnLayoutInfo(uiTab);
            IUIFormTab formTab = uiTab;

            //---------------Assert Precondition----------------
            Assert.AreEqual(2, uiTab.UIColumnLayouts.Count);
            //---------------Execute Test ----------------------
            IUIFormColumn formColumn = formTab[1];
            //---------------Test Result -----------------------
            Assert.IsNotNull(formColumn);
            Assert.AreSame(columnLayout2, formColumn);
        }

        [Test]
        public void Test_IUIFormTab_UIForm_Get()
        {
            //---------------Set up test pack-------------------
            UITab uiTab = TestUtilsUITab.CreateUnsavedValidUITab();
            IUIFormTab formTab = uiTab;
            //---------------Assert Precondition----------------
            Assert.IsNotNull(uiTab.UIFormInfo);
            //---------------Execute Test ----------------------
            IUIForm form = formTab.UIForm;

            //---------------Test Result -----------------------
            Assert.AreSame(uiTab.UIFormInfo, form); ;
        }

        [Test]
        public void Test_IUIFormTab_UIForm_Set()
        {
            //---------------Set up test pack-------------------
            IUIFormTab formTab = new UITab();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            try
            {
                formTab.UIForm = new UIForm();
                Assert.Fail("Expected to throw an NotImplementedException");
            }
            //---------------Test Result -----------------------
            catch (NotImplementedException ex)
            {
                StringAssert.Contains("Please set this via the UIFormInfo relationship.", ex.Message);
            }
        }

        [Test]
        public void Test_CreateNewUIColumnLayouts_ShouldSetOrdinals()
        {
            //---------------Set up test pack-------------------
            UITab uiTab = new UITab();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            UIColumnLayout uiColumnLayout1 = uiTab.UIColumnLayouts.CreateBusinessObject();
            UIColumnLayout uiColumnLayout2 = uiTab.UIColumnLayouts.CreateBusinessObject();
            UIColumnLayout uiColumnLayout3 = uiTab.UIColumnLayouts.CreateBusinessObject();
            UIColumnLayout uiColumnLayout4 = uiTab.UIColumnLayouts.CreateBusinessObject();
            UIColumnLayout uiColumnLayout5 = uiTab.UIColumnLayouts.CreateBusinessObject();
            UIColumnLayout uiColumnLayout6 = uiTab.UIColumnLayouts.CreateBusinessObject();
            //---------------Test Result -----------------------
            TestUtilsShared.AssertItemsAreInOrder(uiColumnLayout1, uiColumnLayout2, uiColumnLayout3, uiColumnLayout4, uiColumnLayout5, uiColumnLayout6);
        }
        [Test]
        public void Test_GetParent()
        {
            //---------------Set up test pack-------------------
            UIFormInfo uiFormInfo = new UIFormInfo();
            UITab uiTab = new UITab();
            uiFormInfo.UITabs.Add(uiTab);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            IModelElement parent = ((IModelElement)uiTab).Parent;
            //---------------Test Result -----------------------
            Assert.AreSame(uiFormInfo, parent);
        }

        [Test]
        public void Test_SetParentExceptionThrown()
        {
            //---------------Set up test pack-------------------
            IModelElement prop = new UITab();

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            Exception exceptionThrown = null;
            try
            {
                prop.Parent = new UIFormInfo();
            }
            catch (Exception ex)
            {
                exceptionThrown = ex;
            }
            //---------------Test Result -----------------------
            Assert.IsNotNull(exceptionThrown);
            Assert.IsInstanceOf(typeof(HabaneroDeveloperException), exceptionThrown);
            StringAssert.Contains
                ("Set the parent of the UITab by setting the related UIFormInfo object", exceptionThrown.Message);
        }
 
    }
}